package com.yeming.flink.practice

import org.apache.flink.api.scala._
import org.apache.flink.api.scala.DataSet

object BatchWordCount {

  def main(args: Array[String]): Unit = {
    //initialize environment variable
    val env = ExecutionEnvironment.getExecutionEnvironment
    //use relative path to get resource
    val url = getClass.getResource("/test.txt")
    // read data
    val data: DataSet[String] = env.readTextFile(url.getPath)
    // handle data
    data.flatMap(_.split(" "))
      .map((_,1))
      .groupBy(0)
      .sum(1)
      .print()
  }

}
